package com.dant.components
{
	import com.dant.events.RubberBandSizeEvent;
	
	import flash.events.EventDispatcher;
	
	import mx.controls.Label;
	import mx.core.UIComponent;
	import mx.core.UITextField;

	public class RubberBand extends UIComponent
	{
		
		public static const sizeDispatcher : EventDispatcher = new EventDispatcher ( );
		
		private var textField:UITextField = new UITextField();

		public function RubberBand()
		{
			super();

			sizeDispatcher.addEventListener( RubberBandSizeEvent.SET_SIZE , setSize );
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			addChild(textField);
		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
				
			// Draw rubber band with a 1 pixel border, and a grey fill. 				
			graphics.clear();								
			graphics.lineStyle(1);
			graphics.beginFill(0xCCCCCC, 0.5);
			graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
			
			textField.text = "Width: "+ unscaledWidth +" - Height: "+ unscaledHeight;
			textField.x = unscaledWidth - textField.measuredWidth - 10;
			textField.y = unscaledHeight - textField.measuredHeight - 10;;
		}
		
		protected function setSize ( event : RubberBandSizeEvent ) : void
		{
			move(event.x,event.y);
			setActualSize(event.width,event.height);
/* 			x = event.x;
			y = event.y;
			width = event.width;
			height = event.height;
 */		}
	}
}